 /**
 * Description: 系统用户vo
 * Copyright:Copyright 2018 nfky.com. All rights reserved
 * @author:xk
 * @since:0.0.1
 * Create at:2018-01-10 下午 19:40:19
 *  
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2018-01-10   xk       0.0.1     Initial
 */
package com.metro.paperless.sys.beans.vo;

import com.metro.core.user.User;
import com.metro.paperless.common.beans.constant.DicTypeEnum;
import com.metro.paperless.common.utils.DicUtil;
import com.metro.utils.CollectionUtil;
import com.metro.utils.DateUtil;
import com.metro.utils.StringUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.metro.paperless.sys.beans.entity.SysUserEntity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

 /**
 * 系统用户vo<br>
 *
 * @author xk
 * @since [0.0.1]
 * @version [0.0.1, 2018-01-10]
 */
@Data()
@EqualsAndHashCode(callSuper = false)
public class SysUser extends SysUserEntity implements User {
     private String newPass;
     private String newPassConfirm;
     private List<SysRole> roles;
     
     
     private String idNumber;
     private Date addTime;

     //角色id字符串
     private String roleIds;

     /**
      * 获取用户id
      *
      * @return 用户唯一标识
      */
     @Override
     public Long getUserId() {
         return super.getId();
     }

     /**
      * 获取用户账号
      *
      * @return 用户登录账号
      */
     @Override
     public String getUserAccount() {
         return super.getAccount();
     }

     /**
      * 获取用户姓名
      *
      * @return 用户展示名
      */
     @Override
     public String getUserName() {
         return super.getName();
     }


     /**
      * 获取当前用户的角色id字符串，以','隔开
      * @return 11,12,22
      */
     public String getRoleIds(){
         if(StringUtil.isNotEmpty(this.roleIds)){
             return this.roleIds;
         }
         StringBuilder sb = new StringBuilder();
         if(CollectionUtil.isNotEmpty(roles)){
             for(SysRole role : roles){
                 sb.append(',').append(role.getId());
             }
             this.roleIds = sb.substring(1);
             return roleIds;
         }
         return null;
     }

     /**
      * 获取当前用户的角色字符串，以','隔开
      * @return 管理员,员工
      */
     public String getRoleName(){
         StringBuilder sb = new StringBuilder();
         if(CollectionUtil.isNotEmpty(roles)){
             for(SysRole role : roles){
                 sb.append(',').append(role.getName());
             }
             this.roleIds = sb.substring(1);
             return roleIds;
         }
         return null;
     }

     /**
      * 根据角色id构建用户角色对应关系列表
      * @return
      */
     public List<SysUserRole> buildUserRoleList(){
         if(this.getRoleIds() != null){
             String[] roleArr = this.getRoleIds().split(",");
             List<SysUserRole> userRoles = new ArrayList<>(roleArr.length);
             SysUserRole userRole = null;
             for (String roleId : roleArr){
                 userRole = new SysUserRole();
                 userRole.setRoleId(Long.valueOf(roleId));
                 userRole.setUserId(this.getId());
                 userRoles.add(userRole);
             }
             return userRoles;
         }
         return null;
     }

     public String getDepartmentStr(){
         return DicUtil.getName(DicTypeEnum.DEPARTMENT, super.getDepartmentId());
     }

     public String getStatusStr(){
         return DicUtil.getName(DicTypeEnum.USER_LOCK_STATUS, super.getStatus());
     }
     
     public String getAddTimeStr() {
         return DateUtil.limitDay(this.addTime);
     }
     
}
